package com.wzy.service.impl;
import com.wzy.dao.ResidentialPassDao;
import com.wzy.pojo.ExternalPopulation;
import com.wzy.pojo.ResidentialPass;
import com.wzy.service.ExternalPopulationService;
import com.wzy.service.ResidentialPassService;
import com.wzy.utils.Utils;
import org.apache.ibatis.session.SqlSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service("residentialPassService")
public class ResidentialPassServiceImpl  implements ResidentialPassService {
    @Autowired
    private ExternalPopulationService externalPopulationService;
    SqlSession sqlSession = Utils.getSqlSession();
    ResidentialPassDao residentialPassDao  =sqlSession.getMapper(ResidentialPassDao.class);
    @Override
    public ResidentialPass findResidentialPass(String ID) {
        return null;
    }

    @Override
    public List<ResidentialPass> findAllResidentialPass() {
        return residentialPassDao.findAllResidentialPass();
    }

    @Override
    public boolean addResidentialPass(ResidentialPass r) {
        if(externalPopulationService.findExternalPopulation(r.getID_number())==null) {
            residentialPassDao.addResidentialPass(r);
            ExternalPopulation e = new ExternalPopulation();
            e.setID_number(r.getID_number());
            e.setResidential_pass("是");
            externalPopulationService.addExternalPopulation(e);
            return true;
        }else {
            return false;
        }

    }

    @Override
    public void deleteResidentialPass(String ID) {
        externalPopulationService.deleteExternalPopulation(ID);
        residentialPassDao.deleteResidentialPass(ID);

    }

    @Override
    public void updateResidentialPass(ResidentialPass r) {
        residentialPassDao.updateResidentialPass(r);

    }
}
